﻿using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using DiagramDesigner.Common.Services.Interfaces;

namespace DiagramDesigner.Common.Services.Impolementation
{
    [Export(typeof(IPluginsLoaderService<>))]
    internal class PluginsLoader<TPlugin> : IPluginsLoaderService<TPlugin>
    {
        [ImportMany]
        IEnumerable<TPlugin> Plugins { get; set; }

        public IEnumerable<TPlugin> GetPlugins()
        {
            AggregateCatalog catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\Plugins\Shapes"));
            catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\Plugins\Behaviours"));
            CompositionContainer container = new CompositionContainer(catalog);
            container.ComposeParts(this);
            return Plugins;
        }
    }
}
